package com.orange.off.cloud.cloudoff.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.Window;

import com.orange.off.cloud.cloudoff.R;
import com.orange.off.cloud.cloudoff.fragments.Client_AddFragment;
import com.orange.off.cloud.cloudoff.fragments.Client_Add_ChoiceFragment;
import com.orange.off.cloud.cloudoff.fragments.CommAuthenticationFragment;
import com.orange.off.cloud.cloudoff.fragments.CommAuthenticationNoticeFragment;
import com.orange.off.cloud.cloudoff.fragments.ForgetPwdFragment;
import com.orange.off.cloud.cloudoff.fragments.LoginFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalAboutUsFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalAuthenticationFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalCommissionDetailFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalCommissionFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalInformationChangeNameFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalInformationChangePwdFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalInformationFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalNoticeDetailFragment;
import com.orange.off.cloud.cloudoff.fragments.PersonalNoticeFragment;
import com.orange.off.cloud.cloudoff.fragments.RealEstateCertificationrulesFragment;
import com.orange.off.cloud.cloudoff.fragments.RealEstateCommissionFragment;
import com.orange.off.cloud.cloudoff.fragments.RegisteredFragment;


/**
 * 小碎片集合
 *
 * @author smile
 */
public class IntermediaryActivity extends FragmentActivity {
    public static final int LOGIN = 0;                                                      // 登录
    public static final int REGISTERED = 1;                                                 // 注册
    public static final int MYPROFILE = 2;                                                  // 我的资料
    public static final int NOTICE = 3;                                                     // 我的通知
    public static final int MYCOMMISSION = 4;                                               // 我的佣金
    public static final int AUTHENTICATION = 5;                                             // 身份认证
    public static final int ABOUTUS = 6;                                                    // 关于我们
    public static final int COMMAUTHENTICATION = 7;                                         // 身份认证，通用界面！！！
    public static final int CHANGENAME = 8;                                                 // 修改姓名
    public static final int CHANGEPWD = 9;                                                  // 修改密码
    public static final int FORGETPWD = 10;                                                 // 忘记密码


    public static final int CLIENT_ADD = 100;                                               // 我的客户---推荐客户
    public static final int CLIENT_ADD_CHOICE = 101;                                        // 我的客户---推荐客户---选择楼盘
    public static final int PERSONAL_NOTICEDETAIL_FRAGMENT = 102;                           // 我的客户---我的通知---详情
    public static final int REAL_ESTATE_CERTIFICATION_RULES_FRAGMENT = 103;                 // 楼盘资源--报备规则
    public static final int REAL_ESTATE_COMMISSION_FRAGMENT = 104;                          // 楼盘资源--佣金奖励
    public static final int COMM_AUTHENTICATION_NOTICE_FRAGMENT = 105;                      // 认证须知
    public static final int PERSONAL_COMMISSION_DETAIL_FRAGMENT = 106;                      // 我的佣金--详情

    Fragment openFragment = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.intermediary_fragment);
        int type = getIntent().getIntExtra("type", LOGIN);

        switch (type) {
            case LOGIN:
                openFragment = LoginFragment.newInstance();
                break;
            case REGISTERED:
                openFragment = RegisteredFragment.newInstance();
                break;
            case MYPROFILE:// 我的资料
                openFragment = PersonalInformationFragment.newInstance(getIntent().getBundleExtra("bundle"));
                break;
            case NOTICE:// 我的通知
                openFragment = PersonalNoticeFragment.newInstance();
                break;
            case MYCOMMISSION:// 我的佣金
                openFragment = PersonalCommissionFragment.newInstance();
                break;
            case AUTHENTICATION:// 身份认证
                openFragment = PersonalAuthenticationFragment.newInstance();
                break;
            case ABOUTUS:// 关于我们
                openFragment = PersonalAboutUsFragment.newInstance();
                break;
            case COMMAUTHENTICATION:// 身份认证通用界面
                openFragment = CommAuthenticationFragment.newInstance(getIntent().getStringExtra("project_name"), getIntent().getStringExtra("id")
                        , getIntent().getStringExtra("identity"));
                break;
            case CHANGENAME:// 修改姓名
                openFragment = PersonalInformationChangeNameFragment.newInstance(getIntent().getStringExtra("personalName"));
                break;
            case CHANGEPWD:// 修改密码
                openFragment = PersonalInformationChangePwdFragment.newInstance();
                break;
            case FORGETPWD:// 忘记密码
                openFragment = ForgetPwdFragment.newInstance();
                break;


            case CLIENT_ADD:// 我的客户---推荐客户
                openFragment = Client_AddFragment.newInstance(getIntent().getBundleExtra("bundle"));
                break;
            case CLIENT_ADD_CHOICE:// 我的客户---推荐客户---选择楼盘
                openFragment = Client_Add_ChoiceFragment.newInstance();
                break;
            case PERSONAL_NOTICEDETAIL_FRAGMENT:// 我的客户---我的通知---详情
                openFragment = PersonalNoticeDetailFragment.newInstance(getIntent().getStringExtra("id"));
                break;
            case REAL_ESTATE_CERTIFICATION_RULES_FRAGMENT:// 楼盘资源--报备规则
                openFragment = RealEstateCertificationrulesFragment.newInstance(getIntent().getStringExtra("id"));
                break;
            case REAL_ESTATE_COMMISSION_FRAGMENT:// 楼盘资源--报备规则
                openFragment = RealEstateCommissionFragment.newInstance(getIntent().getStringExtra("id"));
                break;
            case COMM_AUTHENTICATION_NOTICE_FRAGMENT:// 楼盘资源--报备规则
                openFragment = CommAuthenticationNoticeFragment.newInstance();
                break;
            case PERSONAL_COMMISSION_DETAIL_FRAGMENT:// 我的佣金--详情
                openFragment = PersonalCommissionDetailFragment.newInstance(getIntent().getBundleExtra("bundle"));
                break;

            default:
                break;
        }
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.add(R.id.intermediary_frame, openFragment);
        transaction.commit();
    }


    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (openFragment instanceof LoginFragment) {
            ((LoginFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof RegisteredFragment) {
            ((RegisteredFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalInformationFragment) {
            ((PersonalInformationFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalNoticeFragment) {
            ((PersonalNoticeFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalCommissionFragment) {
            ((PersonalCommissionFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalAuthenticationFragment) {
            ((PersonalAuthenticationFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalAboutUsFragment) {
            ((PersonalAboutUsFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof CommAuthenticationFragment) {
            ((CommAuthenticationFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalInformationChangeNameFragment) {
            ((PersonalInformationChangeNameFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalInformationChangePwdFragment) {
            ((PersonalInformationChangePwdFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof ForgetPwdFragment) {
            ((ForgetPwdFragment) openFragment).onKeyDown(keyCode, event);
        }


        if (openFragment instanceof Client_AddFragment) {
            ((Client_AddFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof Client_Add_ChoiceFragment) {
            ((Client_Add_ChoiceFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalNoticeDetailFragment) {
            ((PersonalNoticeDetailFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof RealEstateCertificationrulesFragment) {
            ((RealEstateCertificationrulesFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof RealEstateCommissionFragment) {
            ((RealEstateCommissionFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof CommAuthenticationNoticeFragment) {
            ((CommAuthenticationNoticeFragment) openFragment).onKeyDown(keyCode, event);
        }
        if (openFragment instanceof PersonalCommissionDetailFragment) {
            ((PersonalCommissionDetailFragment) openFragment).onKeyDown(keyCode, event);
        }
        return false;
    }
}
